package example

import (
	"fmt"
	"strconv"
	. "test_client/logic/internal"
)

type exampleCommand struct {
}

func init() {
	Skeleton.AfterInit(func() {
		command := new(exampleCommand)
		Skeleton.RegisterCommand("example.echo", "echo user inputs", command.onEcho)
	})
}

func (*exampleCommand) onEcho(args []interface{}) (result interface{}) {
	const argsCount = 2
	if len(args) != argsCount {
		result = fmt.Sprintf("arg count less %v", argsCount)
		return
	}

	content := args[0].(string)
	second := args[1].(string)
	number, err := strconv.Atoi(second)
	if err != nil {
		return err.Error()
	}

	rpc.Echo(content, number)

	return
}
